const http = require('http')
const url = require('url')
const { createProxyMiddleware } = require('http-proxy-middleware')

const server = http.createServer((req, res)=>{
    const urlStr = req.url
    if(/\/x/.test(urlStr)) {
        const proxy = createProxyMiddleware('/x', {
            target: 'https://api.bilibili.com',
            changeOrigin: true
        })
        console.log(urlStr)
        proxy(req, res)
        
        // res.writeHead(200, {
        //     'content-type': 'text/html',
        //     'Access-Control-Allow-Origin': '*'
        // })
        // res.end(urlStr)
    }
})

server.listen(8080, ()=>{
    console.log('localhost:8080')
})